// custom-tab-bar/index.ts
// @ts-ignore
const app = getApp()
Component({
    /**
     * 组件的属性列表
     */
    properties: {},

    /**
     * 组件的初始数据
     */
    data: {
        value: '',
        allList: {
            userList: [
                { value: '/pages/index/index', label: '首页', icon: 'home' },
                { value: '/pages/my/my', label: '我的', icon: 'user' }
            ],
            driverList: [
                { value: '/pages/driver/index/index', label: '首页', icon: 'home' },
                { value: '/pages/driver/my/my', label: '我的', icon: 'user' }
            ]
        },
        list: []
    },

    /**
     * 生命周期函数--监听页面显示
     */
    ready() {
        if (typeof this.getTabBar === 'function' && this.getTabBar()) {
            const page: any = getCurrentPages().pop()
            console.log(page, '---page')
            this.getTabBar().setData({
                value: '/' + page.route
            })
        }
    },

    attached() {
        const type = wx.getStorageSync('user-type')
        if (type) {
            if (type == 1) {
                this.setData({
                    list: this.data.allList.userList
                })
            } else if (type == 2) {
                this.setData({
                    list: this.data.allList.driverList
                })
            }
        } else {
            this.setData({
                list: this.data.allList.userList
            })
        }

        console.log(type, this.data.list)
    },
    methods: {
        async onChange(e: any) {
            const url = e.detail.value
            console.log(e, '---url')
            await wx.switchTab({ url })
        }
    }
})
